<template>
  <transition>
    <div class="app-setting">
      <section class="app-main">
        <mt-cell class="" title="账号绑定此微信" is-link @click.native="handleChangeCode"></mt-cell>
        <mt-cell class="staff-details" title="修改密码" is-link to="/password-modify"></mt-cell>
        <mt-cell class="staff-details" title="退出当前账号" is-link @click.native="handleExit"></mt-cell>
      </section>
    </div>
  </transition>
</template>

<script>
  import { Header,Cell,Toast,MessageBox} from 'mint-ui';
//  Vue.component(Header.name, Header);
export default {
  components:{
    Header,
    Cell,
  },
  data () {
    return {

    }
  },
  mounted(){
    var getCode=(location.href).split('code=')[1];
    var wxcode='';
    if(typeof getCode!=='undefined'){
      wxcode=getCode.split('&')[0];
    }else{
      wxcode=''
    }
    if(wxcode!==''){
      var params = new URLSearchParams();
      params.append('thisUrl',location.href);
      params.append('wxCode',wxcode);
      this.$axios({
        method: 'post',
        url:'gp/bu/oauth!changeAuthorize.do',
        data:params,
      }).then((res)=>{
        if(res.data.statusCode==300){
        window.location.href=res.data.object;
      }else if(res.data.statusCode==200){
        Toast({
          message: '切换成功',
          position: 'middle',
          duration:1500
        });
        setTimeout(()=>{
          this.$router.push({path:'/member-center'})},1500)
      }else{
        Toast({
          message: '绑定错误',
          position: 'middle',
          duration:1500
        });
      }
    });
    }

  },
  methods:{
    handleChangeCode(){
      MessageBox({
        title: '',
        message: '确认绑定此微信?',
        showCancelButton: true
      }).then(action => {
        if(action=='confirm'){
        var getCode=(location.href).split('code=')[1];
        var wxcode='';
        if(typeof getCode!=='undefined'){
          wxcode=getCode.split('&')[0];
        }else{
          wxcode=''
        }
        var params = new URLSearchParams();
        params.append('thisUrl',location.href);
        params.append('wxCode',wxcode);
        this.$axios({
          method: 'post',
          url:'gp/bu/oauth!changeAuthorize.do',
          data:params,
        }).then((res)=>{
        if(res.data.statusCode==300){
          window.location.href=res.data.object;
        }
      });
      }
    });
    },
    handleExit(){
      MessageBox({
        title: '',
        message: '确认退出当前账号?',
        showCancelButton: true
      }).then(action => {
        if(action=='confirm'){
        this.$axios({
          method: 'post',
          url:'gp/login!logout.do'
        }).then((res)=>{
         localStorage.removeItem('phone');
         localStorage.removeItem('password');
        sessionStorage.removeItem('currentName');
        sessionStorage.removeItem('storeType');
        sessionStorage.removeItem('userName');
        sessionStorage.removeItem('isAdmin');
        sessionStorage.removeItem('isShopKeeper');
        sessionStorage.removeItem('linkPhone');
          Toast({
            message: '退出成功,请重新登陆！',
            position: 'middle',
            duration:1500
          });
        setTimeout(()=>{
          this.$router.push({path:'/member-center'})
      },1500)
      });
      }
    });

    },
  }
}
</script>

<!-- Add "scoped" attribute to limit CSS to this component only -->

<style>

  .app-setting .app-main{
    padding:12px 0 0;
  }
  .app-setting .app-main .staff-details{
    margin:0 0 12px;
  }
</style>
